layui.use(['table', 'form'], function() {
	var table = layui.table,
		form = layui.form,
		layedit = layui.layedit;

	/*动态加载阶段下拉框*/
	loadstage("stage", form);
	/*动态加载学校下拉框*/
	form.on('select(stage)', function(data) {
		loadSchool(data.value, "schoolid", form);
	});

	//创建文本编辑器
	var editIndex = layedit.build('informationArea', {
		tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right', 'link', 'unlink', 'face'],
		height: 300
	});

	table.render({
		elem: '#InfoList',
		url: '../cloudinformation/getselhomepageinformaction',
		title: '云平台公布文章列表',
		skin: 'line',
		height: "full-135",
		even: true,
		cols: [
			[{
				type: 'numbers',
				title: '序号',
				width: 100,
				align: "center"
			}, {
				field: 'topic',
				title: '信息标题',
				align: "center"
			}, {
				field: 'type',
				title: '信息类型',
				align: "center",
				templet: '#infoTypeText',
			}, {
				field: 'schoolName',
				title: '学校',
				align: "center"
			}, {
				field: 'publishTime',
				title: '发布时间',
				align: "center"
			}, {
				title: '操作',
				toolbar: '#barDemo',
				align: "center"
			}]
		],
		page: {
			layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
			groups: 5,
			limit: 10,
			limits: [10, 20, 30, 40, 50],
			theme: '#1E9FFF'
		}
	});

	$("#btnselinfo").click(function() {
		var title = $.trim($("#title").val());
		var infotype = $("#infotype").val();
		var schoolid = $("#schoolid").val();
		table.render({
			elem: '#InfoList',
			url: '../cloudinformation/getselhomepageinformaction?infotype=' + infotype + "&title=" + title + "&schoolid=" + schoolid,
			title: '收到信息数据表',
			skin: 'line',
			height: "full-135",
			even: true,
			cols: [
				[{
					type: 'numbers',
					title: '序号',
					width: 100,
					align: "center"
				}, {
					field: 'topic',
					title: '信息标题',
					align: "center"
				}, {
					field: 'type',
					title: '信息类型',
					align: "center",
					templet: '#infoTypeText',
				}, {
					field: 'schoolName',
					title: '学校',
					align: "center"
				}, {
					field: 'publishTime',
					title: '发布时间',
					align: "center"
				}, {
					title: '操作',
					toolbar: '#barDemo',
					align: "center"
				}]
			],
			page: {
				layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
				groups: 5,
				limit: 10,
				limits: [10, 20, 30, 40, 50],
				theme: '#1E9FFF'
			}
		});
		$("#title").val(title);
	})

	//监听行工具事件
	table.on('tool(InfoList)', function(obj) {
		var data = obj.data;
		if(obj.event === 'selcouldInfo') {
			$("#topic").text(data.topic);
			$("#author").html(data.realName);
			$("#pushTime").html(data.publishTime);
			if(data.addtionfile != null && data.addtionfile != "" && data.addtionfile != undefined) {
				$("#enclosure").attr("href", data.addtionfile);
				var addfilestr = (data.addtionfile).split("\\");
				$("#enclosure").text(addfilestr[addfilestr.length - 1]);
			} else {
				$("#addfileicon").hide();
				$("#enclosure").text("暂无附件");
			}
			$("#infoContent").html(data.infoContent);
			var index = layer.open({
				type: 1,
				title: '信息详情',
				area: ['800px', '95%'],
				shade: 0.8,
				content: $('#selinfolayer-con'),
				maxmin: true,
				cancel: function() {
					$(".selinfolayer-con").css("display", "none");
				},
				success: function(layero, index) {
					setTimeout(function() {
						layui.layer.tips('点击此处返回信息列表', '.layui-layer-setwin .layui-layer-close', {
							tips: 3
						});
					}, 500)
				},
			});
			layer.full(index);
		}
		if(obj.event === 'pubcouldInfo') {
			var index = layer.open({
				type: 2,
				title: '文章推送',
				area: ['830px', '95%'],
				shade: 0.8,
				maxmin: true,
				content: ['../articleManagement/issueArticle.jsp?', 'yes'],
				success: function(layero, index) {
					console.log(layero, index);
					var body = layui.layer.getChildFrame('body', index);
					if(data) {
						//alert(data.id)
						body.find("#title").val(data.topic);
						body.find("#realName").val(data.realName);
						body.find("#school").val(data.schoolName);
						body.find("#createtime").val(data.publishTime);
						body.find("#articleCon").append(data.infoContent);
						body.find("#infoid").val(data.id);
						form.render();
					}
					setTimeout(function() {
						layui.layer.tips('点击此处返回信息列表', '.layui-layer-setwin .layui-layer-close', {
							tips: 3
						});
					}, 500)
				},
				cancel: function() {}
			});
			layer.full(index);
		}
	});

});